站内搜索: 请输入搜索关键词

当前页面: 开发资料首页Netbeans 专题Using Java Web Start in NetBeans IDE

Using Java Web Start in NetBeans IDE

摘要: This tutorial provides a step-by-step walk-through of how to use the Netbeans Module for Java Web Start. The tutorial illustrates how to install the plug-in module. You then take the GUI form examples created with Matisse and enable Java Web Start functionality for the projects. Finally, you assemble, deploy, and debug this application in Netbeans IDE 5.0

This tutorial provides a step-by-step walk-through of how to use the Netbeans Module for Java Web Start. The tutorial illustrates how to install the plug-in module. You then take the GUI form examples created with Matisse and enable Java Web Start functionality for the projects. Finally, you assemble, deploy, and debug this application in Netbeans IDE 5.0.

This tutorial assumes that JDK1.5.0 is installed on your computer.

Contents:

Preparation

This section describes how to install NetBeans IDE and the Netbeans Module for Java Web Start.

Obtaining and Installing NetBeans IDE

Use the instructions provided at the above download site to install NetBeans IDE. Choose jdk_home to be the location of your JDK 1.5.0 installation when installing NetBeans IDE.

Starting the IDE

To start the NetBeans IDE:

  • On Microsoft Windows:
    Choose Start > Programs > NetBeans 5.0 > NetBeans IDE.
  • On Solaris, UNIX, or Linux environments:
    Navigate to the bin subdirectory of your installation. Execute the launcher script by typing./netbeans.

Downloading and Installing Netbeans Module for Java Web Start

  1. Open Netbeans IDE 5.0 and connect to the internet.
  2. Inside NetBeans IDE choose Tools > Update Center.
  3. In the Update Center, make sure the checkbox for the NetBeans Update Center Beta is checked. If you are using a development build, choose Development Update Center. Click the Next button to access the Update Center.
  4. After a few moments, the list of available modules comes up. Select the Netbeans Module for Java Web Start from the list as shown below and click the Add button to add the components.

    update center with java web start module selected

  5. Click Next. The Update Wizard asks you to accept the necessary licenses. Read them and click Agree to start downloading the module.
  6. After the download is done, click Next. The Update Wizard shows you an overview of the new module to be installed. Click Finish to complete the installation.
  7. After the module has finished loading, you can use the Java Web Start plugin in your IDE. Congratulations!

To reinstall the plugin to NetBeans IDE, you may need to remove the user directory of NetBeans IDE (it' ilocated at %USER_HOME%/.netbeans/) and restart NetBeans IDE to install.

Creating a New Java Application

In this section, you create a copy of the GUI Form Sample application which is bundled with the IDE. You will add Java Web Start functionality to the application in the later steps.

  1. Inside the IDE, choose File > New Project to open the New Project wizard.

  2. Under Categories, select Samples > General. Under Projects, select GUI Form Examples and click Next.

    creating a MyApp project

  3. In the New Java Application Wizard, leave the name the project as the default GUIFormExamples and place it anywhere on your system. Details about wizard properties can be found here

  4. Click Finish, the application is created.

    The IDE creates the MyProjects/GUIFormExamples folder on your system. This folder contains all of your sources and project metadata, such as the project Ant script. The GUIFormExamples project is opened in both the Projects window and the Files window.

Enabling Java Web Start

You can activate the Java Web Start function at any time with the Enable Java Web Start command. This is a "one-time action ". After you have enabled Java Web Start for a project, the project can be debugged, deployed, and run with Java Web Start.

  1. Right-click the GUIFormExamples project node in the Projects window.

  2. Choose Java Web Start > Enable Java Web Start.

    enabling Java Web Start in the project

    The IDE creates a JNLP config file for the Java application and a web directory for deployment, and adds support for the JNLP serivces API. The JNLP config file is opened in the Source Editor.

Browsing Project Elements

You can view the application's logical structure in the Projects window and its file structure in the Files window.

Browsing in the Logical View

If the Projects window is closed, open it by choosing Window > Projects (Ctrl+1). The Projects window shows a logical view of important project contents, such as Source packages. You can right-click any project node to access a contextual menu of commands for building, running, and debugging the project, as well as opening the Project Properties dialog box.

Browsing in the Physical View

Open the Files window by choosing Window > Files (Ctrl+2). It shows a directory-based view of your projects, including files and folders that are not displayed in the Projects window. From the Files window, you can open and edit your project configuration files, like the project build script and properties file. You can also view build outputs like compiled classes, JAR files, WAR files, and the generated Javadoc documentation.

Editing the JNLP Config File

The JNLP config file describes how to download and launch a particular application. By default, a new JNLP file is created at <ExamplesPath>/ with the necessary elements. You can view and edit the JNLP config file as necessary in the JNLP Editor.

You can open the JNLP file in the Source Editor by double-clicking the JNLP file in the Files window, or by choosing Java Web Start > Edit JNLP from the project's contextural menu. You can edit the JNLP file using JNLP Visual Editor or edit the XML code by hand.

By default, all sections in the Visual Editor are expanded. You can close any section as you want by clicking the section title in the General or Resources tab. The section that you are working on is highlighted.

Defining the JAR Resource

Since the GUI forms were created with Matisse, the program needs the swing-layout-1.0.jar file in order to run. You can see that this JAR file is on the project's classpath by expanding the Libraries node in the Projects window. You have to configure the JNLP file to make this JAR file available when the project is run with Java Web Start.

  1. Open GUIFormExamples.jnlp, if it is not already opened.
  2. In the Resources tab of the visual editor, expand JAR Resources and click Add.
  3. Type dist/lib/swing-layout-1.0.jar in the Href field and eager in the Download field, as shown below.

    Adding a JAR resource

    Note: If you changed the name of the project from the default GUIFormExamples, the IDE normally names the JAR file for the project accordingly to match the project name. In this Matisse sample example, however, the JAR file name is static (in this case, GUIFormExamples.jar) and doesn't change to match the name of the project. In this case, you need to modify the JAR file name in the JNLP file through the visual editor. Under JAR Resources, make sure that the JAR file name for the project is dist/GUIFormExamples.jar.

JNLP Visual Editor: General

The General tab of the Visual Editor is used to edit information specific to the JNLP file itself, the information about the application, and the application descriptor. It includes several sections:

  1. General
    This is the root JNLP element. It has a set of attributes that are used to specify information that is specific to the JNLP file itself. Edit the content in the textfield as necessary.

    • Codebase
      The codebase attribute of the jnlp element. It specifies the codebase for the application.

    • Href
      The href attribute of the jnlp element. It contains the location of the JNLP file as an URL.

  2. Information
    This is the information element. It contains information intended to be consumed by the JNLP client to integrate the application into the desktop, provide user feedback, and etc. Edit the content in the tex tfield or check the checkbox as necessary.

    • Title
      Title element (the name of the application).

    • Vendor
      Vendor element (the name of the vendor of the application).

    • Homepage
      Homepage element (the URL locating the home page for the application).

    • Description
      Description element (a short statement about the application).

    • Icon
      Icon element (Optional). The icon can be used by a JNLP client to identify the application to the user.

    • Start Menu Shortcut
      Menu element (Optional). It is used to indicate an application's preference for putting a menu item in the users
      start menus.

    • Create Desktop Shortcut
      Desktop element (Optional). It is used to indicate an application's preference for putting a shortcut on the users desktop.

    • Run Online
      offline-allowed element (Optional). It indicates if the application can be launched offline.

  3. Application Description
    This application-desc element gives description of the application.

    • Main-class
      main-class attribute of the application-desc element. It describes the main class of an applicaion.

    • Argument
      argument elements. It describe an ordered set of arguments to the application.

JNLP Visual Editor: Resources

The Resources tab of the Visual Editor is used to edit The resources element that used to specify all the resources, such as Java class files, native libraries,and system properties that are part of an application.

  • To add a resource: Multiple resources can be added by clicking the Add button on any resource section and filling in the necessary information for that kind of resource.

  • To delete a resource: Select the target resource in the resource table, then click the Remove button in that section

  • To edit a resource: Select the target resource in the resource table, click the Edit button in that section. This will pop-up the resource detail information dialog. Edit the content as necessary.
  1. Java Run Time Requirement
    The j2se element (sub-element of resources) specifies what Java 2 SE Runtime Environment (JRE)
    versions an application is supported on, as well as standard parameters to the Java Virtual Machine. Several JREs can be specified.

  2. Jar Resources
    The Jar element describes a jar file resource.

  3. Library
    The nativelib element describes a resource containing native files.

  4. System Properties
    The property element describes a name/value pair that is available to the launched application as a system property.

Deploying a Java Application

The Java Project can be deployed to a registered server. The bundled Tomcat Web Server is registered with the IDE automatically.

Setting the Project Main Class

  1. Right-click the project and choose Properties.
  2. Click Run in the left pane of the properties dialog box and type examples.ContactEditor in the Main Class field.
  3. Click OK.

Deploying the Application

  1. Right-click the GUIFormExamples project node in the Projects window.

  2. Choose Java Web Start > Deploy with Java Web Start from the contextural menu.

    The IDE deploys the application to the registered server, starts the server, and opens the default index page. The application can then be launched by clicking the "Click me!" link on that page.

Running the Java Application with Java Web Start

The Java Project can be run either as a standalone Java Application or run with Java Web Start.

Running as a Java Application

Choose Run > Run Main Project or right-click on the project node in the Projects window and choose Run Project. All other runtime settings are the same as for a regular Java project.

Running with Java Web Start

  1. Right-click the GUIFormExamples project node in the Projects window.

  2. Choose Java Web Start > Run with Java Web Start from the contextural menu. The application is launched by Java Web Start, as shown below.

    application deployed with Java Web Start

Debuging a Java Application with Java Web Start

You can use the Sun Microsystems JPDA debugger from the IDE to debug a Java application using Java Web Start.

  1. Set breakpoints and watches in the Java files.

  2. Right-click the GUIFormExamples project node in the Projects window.

  3. Choose Java Web Start > Debug with Java Web Start from the contextural menu.

The application is launched by Java Web Start and debugged into the breakpoints.

New Java Project Wizard Properties

Related Topics

For more information see the following links:


↑返回目录
前一篇: Using Java Persistence in a J2EE 1.4 Web Application
后一篇: Using NetBeans to Develop with the eBay SDK for Java